package com.example.analysis.service.impl;

import com.example.analysis.domain.CompetitionInfo;
import com.example.analysis.domain.ScoreInfo;
import com.example.analysis.entity.CompetitionList;
import com.example.analysis.entity.CompetitionList;
import com.example.analysis.entity.PageBean;
import com.example.analysis.mapper.CompetitionListDao;
import com.example.analysis.service.CompetitionListService;
import com.example.analysis.utils.Response;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CompetitionListServiceImpl implements CompetitionListService {
    @Resource
    private CompetitionListDao CompetitionListDao;

    @Override
    public Response<CompetitionList> insert(CompetitionList aEvaluateListStudentList) {
        try {
            CompetitionListDao.insert(aEvaluateListStudentList);
            return new Response<>(true, "Insert success", null);
        } catch (Exception e) {
            return new Response<>(false, "Insert failed: " + e.getMessage(), null);
        }
    }

    @Override
    public Response<List<CompetitionList>> getById(String competitionId,String studentId) {
        List<CompetitionList> aEvaluateListStudentList = CompetitionListDao.selectByPrimaryKey(competitionId,studentId);
        if (aEvaluateListStudentList != null) {
            return new Response<>(true, "Success", aEvaluateListStudentList);
        } else {
            return new Response<>(false, "Administration not found", null);
        }
    }

    @Override
    public PageBean getAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<CompetitionInfo> scoreInfoList=CompetitionListDao.getAll();
        Page p=(Page) scoreInfoList;
        long total=p.getTotal();
        List result=p.getResult();
        PageBean pageBean=new PageBean();
        pageBean.setTotal(total);
        pageBean.setRows(result);//返回总条数和具体数据
        return pageBean;
    }
}
